home *** CD-ROM | disk | FTP | other *** search
- /*
- * FM
- *
- * A other kind of lines. Lines with a color range !
- *
- * (c) by VIONA-Development 1992/94
- */
-
- #include <exec/types.h>
- #include <proto/exec.h>
- #include <egs/egsintui.h>
- #include <egs/proto/egsintui.h>
- #include <egs/egsgfx.h>
- #include <egs/proto/egsgfx.h>
- #include <egs/egs.h>
- #include <egs/proto/egs.h>
-
- long RangeRand(int i );
-
- /* die Zeiger auf unsere Libraries */
- struct Library *EGSIntuiBase;
- struct Library *EGSGfxBase;
- struct Library *EGSBase;
-
-
- /* Beschreibung einer Linie */
- struct Line
- {
- int used;
- long x1,y1;
- long x2,y2;
- };
-
-
- /* Ausgabe eines regelmäßigen Sterns mit 4 Spitzen */
- void drawRect( EI_WindowPtr window, ULONG color,
- struct Line *line1,
- struct Line *line2 )
- {
- EG_RastPortPtr rp = window->RPort;
- long top = window->BorderTop;
- long left = window->BorderLeft;
-
- EG_SetAPen( rp, color );
- EG_AreaMove( rp, left+line1->x1, top+line1->y1 );
- EG_AreaDraw( rp, left+line2->x1, top+line2->y1 );
- EG_AreaDraw( rp, left+line2->x2, top+line2->y2 );
- EG_AreaDraw( rp, left+line1->x2, top+line1->y2 );
- EG_AreaEnd( rp );
- }
-
-
- /* und hier passiert etwas */
- #define MAX_HISTORY 20
- #define SPEED 11
- #define COLORSPEED 6
-
- void doThings( EI_WindowPtr window )
- {
-
- struct EG_AreaInfo areaInfo;
- EG_Polygon areaBuffer[20];
- struct Line history[MAX_HISTORY];
- long x1,y1, x2,y2;
- long dx1,dy1, dx2,dy2;
- long dtime;
- ULONG color;
- ULONG dcolor;
- int historyPos;
- int i;
-
- /* TmpRas anlegen */
- window->RPort->AreaInfo = EG_InitArea( &areaInfo, &areaBuffer[0],20 );
- window->RPort->TmpRas = E_AllocBitMap( window->Width,
- window->Height,1,E_PIXELMAP,0,
- window->WScreen->EScreen->Map);
-
- /* History löschen */
- for( i=0; i<MAX_HISTORY; i++ ) history[i].used = 0;
-
- /* Startwert bestimmen */
- x1 = RangeRand( window->Width-1 );
- y1 = RangeRand( window->Height-1 );
- x2 = RangeRand( window->Width-1 );
- y2 = RangeRand( window->Height-1 );
- dtime = 1;
- color = window->WinColors.Back;
- if (color % 256 != 0)
- {
- color = E_GetRGB8( window->WScreen->EScreen,color);
- }
- /* Anmimationschleife */
- historyPos = 1;
- history[0].x1 = x1;
- history[0].y1 = y1;
- history[0].x2 = x2;
- history[0].y2 = y2;
- history[0].used = 1;
- while( GetMsg( window->UserPort )==NULL )
- {
- /* das alte Stück entfernen */
- if ( history[historyPos].used )
- {
- drawRect( window, window->WinColors.Back,
- &history[historyPos],
- &history[(historyPos+1) % MAX_HISTORY] );
- }
-
- /* alles einen Schritt bewegen */
- dtime--;
- if ( dtime==0 )
- {
- dx1 = RangeRand( 2*SPEED ) - SPEED;
- dy1 = RangeRand( 2*SPEED ) - SPEED;
- dx2 = RangeRand( 2*SPEED ) - SPEED;
- dy2 = RangeRand( 2*SPEED ) - SPEED;
- dcolor = (((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 24) +
- (((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 16) +
- (((RangeRand(2*COLORSPEED) + 256 - COLORSPEED) % 256) << 8);
- dtime = RangeRand( 100 ) + 10;
- }
- x1 += dx1;
- if ( x1<0 || x1>=window->Width ) { x1 -= dx1; dx1 = -dx1; }
- y1 += dy1;
- if ( y1<0 || y1>=window->Height ) { y1 -= dy1; dy1 = -dy1; }
- x2 += dx2;
- if ( x2<0 || x2>=window->Width ) { x2 -= dx2; dx2 = -dx2; }
- y2 += dy2;
- if ( y2<0 || y2>=window->Height ) { y2 -= dy2; dy2 = -dy2; }
- color += dcolor;
-
- /* den neuen Wert speichern */
- history[historyPos].x1 = x1;
- history[historyPos].y1 = y1;
- history[historyPos].x2 = x2;
- history[historyPos].y2 = y2;
- history[historyPos].used = 1;
-
- /* das neue Stück ausgeben */
- drawRect( window, color,
- &history[(historyPos+MAX_HISTORY-1) % MAX_HISTORY],
- &history[historyPos]);
-
- /* den zyklischen Puffer weiterführen */
- historyPos = (historyPos + 1) % MAX_HISTORY;
- }
- }
-
-
- /* das Hauptprogramm */
- void main( int argc, char *argv[] )
- {
- static struct EI_NewWindow newWindow =
- {
- 50,30, 400,300,
- 0,0, 0,0,
- NULL,
- EI_WINDOWCLOSE | EI_WINDOWBACK | EI_WINDOWDRAG,
- NULL,
- "Testfenster",
- EI_SMART_REFRESH,
- EI_iCLOSEWINDOW,
- NULL,
- {0,0,0,0,0,0,0},
- NULL,
- NULL
- };
- EI_WindowPtr window;
-
- /* die Libraries öffnen */
- EGSIntuiBase = OpenLibrary( (UBYTE *)"egsintui.library", 0 );
- if ( EGSIntuiBase )
- {
- EGSGfxBase = OpenLibrary( (UBYTE *)"egsgfx.library", 0 );
- if ( EGSGfxBase )
- {
- EGSBase = OpenLibrary( (UBYTE *)"egs.library", 0 );
- if ( EGSBase )
- {
- window = EI_OpenWindow( &newWindow );
- if ( window )
- {
- doThings( window );
- EI_CloseWindow( window );
- }
- CloseLibrary( EGSBase );
- }
- CloseLibrary( EGSGfxBase );
- }
- CloseLibrary( EGSIntuiBase );
- }
- }
-